package com.example.taigame;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.adapter.main_fragment_adapter;
import com.example.utils.Utils;

public class GroupGameActivity extends BaseActivity {

	private int gameType;
	private GridView gridView;
	private TextView name;
	private ImageView home;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.group_game_activity);
		gameType = getIntent().getIntExtra("gameType", 1);
		initView();
	}

	private void initView() {
		gridView = (GridView) findViewById(R.id.gridView1);
		home = (ImageView) findViewById(R.id.imageView1);
		name = (TextView) findViewById(R.id.textView1);

		gridView.setAdapter(new main_fragment_adapter(getApplicationContext(),
				gameType));
		name.setText(Utils.gameName[gameType]);
		home.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				MyApp.currentSelectedGame = MyApp.listGameType.get(gameType)
						.getListGame().get(arg2);
				Intent intent = new Intent(MyApp._currentActivity,
						GameDetail.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				MyApp._currentActivity.startActivity(intent);

			}
		});
	}

}
